const express = require("express");
const { Category } = require("../models/index");
const { success, fail } = require("../utils/response");

const router = express.Router();

// 获取分类，按从大到小排，带出课程
router.get("/", async (req, res) => {
  try {
    const conditions = {
      order: [
        ["rank", "ASC"],
        ["id", "DESC"],
      ],
    };
    const rows = await Category.findAll(conditions);
    console.log("get categories", rows);
    success(res, "get categories success", rows);
  } catch (error) {
    console.log(error);
    fail(res, error);
  }
});

module.exports = router;
